#include <string.h>

#include "coder.h"


void Coder::SetBuf( char *cpBuf )
{
	cpCoderBegin = cpBuf;
	cpCoderEnd = cpBuf + HEADERSIZE;
}

int Coder::SetHeader( short sType )
{
	short					iSize;

	iSize = cpCoderEnd - cpCoderBegin - HEADER_TOTAL_SIZE;
	memcpy( cpCoderBegin, &iSize, sizeof( short ) );
	memcpy( cpCoderBegin + sizeof( short ), &sType, sizeof( short ) );

	return iSize + HEADER_TOTAL_SIZE;
}

void Coder::GetHeader( short *sBodySize, short *sType )
{
	memcpy( sBodySize, cpCoderBegin, sizeof( short ) );
	memcpy( sType, cpCoderBegin + sizeof( short ), sizeof( short ) );
}

void Coder::PutChar( char cData )
{
	*cpCoderEnd = cData;
	cpCoderEnd ++;
}

void Coder::GetChar( char *cpData )
{
	*cpData = *cpCoderEnd;	
	cpCoderEnd ++;
}

void Coder::PutShort( short sData )
{
	memcpy( cpCoderEnd, &sData, sizeof( short ) );
	cpCoderEnd += sizeof( short );
}

void Coder::GetShort( short *sData )
{
	memcpy( sData, cpCoderEnd, sizeof( short ) );
	cpCoderEnd += sizeof( short );
}

void Coder::PutInt( int iData )
{
	memcpy( cpCoderEnd, &iData, sizeof( int ) );
	cpCoderEnd += sizeof( int );
}

void Coder::GetInt( int *iData )
{
	memcpy( iData, cpCoderEnd, sizeof( int ) );
	cpCoderEnd += sizeof( int );
}

void Coder::PutText( const char *cpData, int iSize )
{
	memcpy( cpCoderEnd, cpData, iSize );
	cpCoderEnd += iSize;
}

void Coder::GetText( char *cpData, int iSize )
{
	memcpy( cpData, cpCoderEnd, iSize );
	cpCoderEnd += iSize;
}
